/*
Date:20210831 4:22PM
key:滑动窗口算是比较熟悉了
*/
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int l=0,r=0,copek=k,maxlen=0;

        for(r=0;r<nums.size();r++)
        {
            if(nums[r]==1)
            {
                //refreash
                if(maxlen<r-l+1)
                {
                    maxlen=r-l+1;
                }
            }
            else
            {
                if(copek>0)
                {
                    copek--;
                    //refreash
                    if(maxlen<r-l+1)
                    {
                        maxlen=r-l+1;
                    }
                }
                else
                {
                    while(nums[l]!=0&&l<r){l++;}
                    l++;
                }
            }
        }
        return maxlen;
    }
};